var curPage = 1; //当前页码 
var total,pageSize,totalPage,input,cokkieArr=''; //总记录数，每页显示数，总页数

//获取数据 
function getData(page,op,ckname,listData,key,cookieId){ 
cokkieArr=cookieId;
    $.ajax({ 
        type: 'POST', 
        url: 'ajaxMailData', 
        data: {'pageNum':page-1,'op':op,'keywords':key}, 
        dataType:'json', 
        success:function(json){ 
            $("#"+listData).empty();//清空数据区 
            total = json.total; //总记录数 
            pageSize = json.pageSize; //每页显示条数 
            curPage = page; //当前页 
            totalPage = json.totalPage; //总页数 
            var tr = ""; 
            var list = json.list;
			var pArray = new Array();
			var cid='';
			if(list!=null){ 
				$.each(list,function(index,array){ //遍历json数据列
					var name = array['userName'] ? array['userName'] : array['name']; 
					var tel = array['tel'] ? array['tel'] : array['phone'];
					var id = array['adminId'] ? array['adminId'] : array['id'];
					var input='';

					if(checkInput(cokkieArr, id)) {
							input = "<input name='" + ckname + "' type='checkbox' checked  class='cb' onclick=cookieData('"+ckname+"');  value=" + id + " />";
						} else {
							input = "<input name='" + ckname + "' type='checkbox'  class='cb' onclick=cookieData('"+ckname+"');  value=" + id + " />";
						}
					tr += " <tr ><td>"+input+"</td><td>"+name+"</td><td>"+array['name']+"</td><td>"+tel+"</td><td>"+array['email']+" </td></tr>";
					
				}); 
				$("#"+listData).append(tr); 
			}
        }, 
        complete:function(){ //生成分页条 
            getPageBar(op); 
			
        }, 
        error:function(){ 
            alert("数据加载失败"); 
        } 
    }); 
}

function checkInput(cokkieArr, id) {
    var cid = false;
    if (cokkieArr != null || cokkieArr != undefined) {
		pArray = cokkieArr.split(',');
        if (pArray.indexOf(id) > -1) {
            cid = true;
        } else {
            cid = false;
        }
    }
    return cid;
}
 
//获取分页条 
function getPageBar(op){ 
    //页码大于最大页数 
    if(curPage>totalPage) curPage=totalPage; 
    //页码小于1 
    if(curPage<1) curPage=1; 
    pageStr = "<span>共"+total+"条</span><span>"+curPage 
    +"/"+totalPage+"页</span>"; 
     if(totalPage>1){
    //如果是第一页 
    if(curPage==1){ 
        pageStr += "<span>首页</span><span>上一页</span>"; 
    }else{ 
        pageStr += "<span><a href='javascript:void(0)' rel='1'>首页</a></span> <span><a href='javascript:void(0)' rel='"+(curPage-1)+"'>上一页</a></span"; 
    } 
     
    //如果是最后页 
    if(curPage>=totalPage){ 
        pageStr += "<span>下一页</span><span>尾页</span>"; 
    }else{ 
        pageStr += "<span><a class='_ajaxpage' href='javascript:void(0)' rel='"+(parseInt(curPage)+1)+"'> 下一页</a></span><span><a href='javascript:void(0)' rel='"+totalPage+"'>尾页</a></span> "; 
    } 
	 }
   
    $("#"+op).html(pageStr); 
} 